package assignmentstrategy

import (
	"codejy/analysis/codeanalysis"
	"codejy/store"
	"codejy/structdef"
	"strings"
)

type InstanceAddressPropStrategy struct {
}

func init() {
	RegisterStrategy(&InstanceAddressPropStrategy{})
}
func (n InstanceAddressPropStrategy) getId() int {
	return codeanalysis.InstanceAddressProp
}

func (n InstanceAddressPropStrategy) Execute(threadStore *structdef.ThreadStore, code string) string {
	//通过 实例地址.属性名称,获取值
	//截取实例地址,,获取最后@#@位置
	index := strings.LastIndex(code, "@#@.")
	instanceAddress := code[:index+3]
	propName := code[index+4:]
	prop, _ := store.GetInstanceProp(threadStore, instanceAddress)
	definition, p := prop[propName]
	if p {
		return definition.Value
	} else {
		typeName, _ := prop["@TYPENAME@"] //获取实例的类型名称
		panic("错误::::::" + typeName.Value + "类型中没有" + code + "的成员变量定义")
	}
}
